package com.hl.card.credit.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.hl.card.credit.pub.model.PublicOrdersAllModel;
import com.hl.card.credit.pub.utils.CommonUtil;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 正常业务订单表(同一订单内，每个人的业务信息除价格可以不同外，其他数据必须一致，否则必须下新订单)
 * </p>
 *
 * @author jobob
 * @since 2018-11-06
 */
@TableName("public_orders")
public class PublicOrders implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @TableId(value = "busines_order_id", type = IdType.AUTO)
    private Integer busines_order_id;

    /**
     * 订单号
     */
    private String order_code;

    /**
     * 订单生成日期
     */
    private Date create_date;

    /**
     * 订单生成时间
     */
    private Date order_time;

    /**
     * 业务种类（机票、火车票。。。)
     */
    private String busines_species;

    /**
     * 所属商户（商户代码）
     */
    private String merchant_code;

    /**
     * 订单来源（商户应用）
     */
    private String source;

    /**
     * 上级商户（与所属商户实行双级定位）
     */
    private String cid_merchant;

    /**
     * 所属客户（客户代码）
     */
    private String customer_id;

    /**
     * 订单状态
     */
    private String order_status;

    /**
     * 订单标签
     */
    private String order_tag;

    /**
     * 财务状态（欠款、部份欠款、结清）
     */
    private String finance_status;

    /**
     * 成人人数（冗余）
     */
    private Integer adult_num;

    /**
     * 儿童人数（冗余）
     */
    private Integer children_num;

    /**
     * 婴儿人数（冗余）
     */
    private Integer inf_num;

    /**
     * 订单总价（冗余）
     */
    private Double order_all_price;

    /**
     * 总销售价（不含税）（冗余）
     */
    private Double sale_price;

    /**
     * 总税（无税产品为0）（冗余）
     */
    private Double tax;

    /**
     * 保险数量
     */
    private Integer i_num;

    /**
     * 保险总价（冗余）
     */
    private Double i_price;

    /**
     * 总快递费（冗余）
     */
    private Double express_price;

    /**
     * 总服务费（冗余）
     */
    private Double service_price;

    /**
     * 其他收费（收为正数，支为负）（冗余）
     */
    private Double other_price;

    /**
     * 联系人
     */
    private String contact;

    /**
     * 联系人电话
     */
    private String telephone;

    /**
     * 联系人手机号
     */
    private String phone_number;

    /**
     * 联系人地址
     */
    private String address;

    /**
     * 是否锁定
     */
    private Integer is_lock;

    /**
     * 锁定人
     */
    private String lock_user;

    /**
     * 是否审核（订单、财务、帐单全部核对的结果）
     */
    private Integer is_examine;

    /**
     * 订单是否有效（删除）
     */
    private Integer is_effect;

    /**
     * 补充信息（json）
     */
    private String remark;

    /**
     * 审核人
     */
    private String examine_er;

    /**
     * 审核时间
     */
    private Date examine_time;

    /**
     * 生效时间
     */
    private Date start_datetime;

    /**
     * 失效时间
     */
    private Date end_datetime;

    /**
     * 是否使用发票0否1是
     */
    private Integer is_receipt;

    /**
     * (客规,机票专用)
     */
    private String flight_regulation;

    private String link_type;

    private String link_merchantCode;

    public static PublicOrders Init(Map<String, Object> map, PublicOrdersAllModel model) {
        PublicOrders porders = new PublicOrders();
        // 生成订单号，需要拿到业务种类，商家标识，业务类型等字符串，然后组装年月日时分秒+三位计数器
        porders.setOrder_code(model.getOrder_code());
        porders.setCreate_date(new Date());
        porders.setOrder_status(model.getOrder_status());
        porders.setOrder_time(model.getOrder_time());
        porders.setIs_effect(1);
        porders.setBusines_species(model.getBusines_species());
        porders.setLink_merchantCode(model.getLink_merchantCode());
        porders.setLink_type(model.getLink_type());
        if(CommonUtil.isEmpty(model.getOther_price()))
            porders.setOther_price(0d);
        else
            porders.setOther_price(model.getOther_price());
        porders.setMerchant_code(model.getMerchant_code());
        porders.setSource(model.getSource());
        porders.setCid_merchant(model.getCid_merchant());

        porders.setCustomer_id(model.getCustomer_id());
        porders.setOrder_status(model.getOrder_status());
        porders.setFinance_status(model.getFinance_status());
        porders.setAdult_num(model.getAdult_num());
        porders.setChildren_num(model.getChildren_num());

        porders.setInf_num(model.getInf_num());
        // 价格相关
        porders.setOrder_all_price(model.getOrder_all_price());
        porders.setSale_price(model.getSale_price());
        porders.setTax(model.getTax());

        if (CommonUtil.isNotEmpty(model.getI_price()))
            porders.setI_price(model.getI_price());
        else
            porders.setI_price(0d);
        if (CommonUtil.isNotEmpty(model.getExpress_price()))
            porders.setExpress_price(model.getExpress_price());
        else
            porders.setExpress_price(0d);

        if (CommonUtil.isNotEmpty(model.getService_price()))
            porders.setService_price(model.getService_price());
        else
            porders.setService_price(0d);
        if (CommonUtil.isNotEmpty(model.getOther_price()))
            porders.setOther_price(model.getOther_price());
        else
            porders.setOther_price(0d);

        porders.setContact(model.getContact());
        porders.setTelephone(model.getTelephone());
        porders.setPhone_number(model.getPhone_number());
        porders.setAddress(model.getAddress());

        porders.setIs_lock(0);// 锁定相关
        porders.setLock_user(model.getLock_user());
        if(CommonUtil.isEmpty(model.getIs_examine()))
            porders.setIs_examine(0);// 审核相关
        else
            porders.setIs_examine(model.getIs_examine());
        if(CommonUtil.isEmpty(model.getExamine_er()))
            porders.setExamine_er("");
        else
            porders.setExamine_er(model.getExamine_er());
        if(CommonUtil.isNotEmpty(model.getStart_datetime()))
            porders.setStart_datetime(model.getStart_datetime());
        if(CommonUtil.isNotEmpty(model.getEnd_datetime()))
            porders.setEnd_datetime(model.getEnd_datetime());
        porders.setExamine_time(null);

        porders.setRemark(null);
        if(CommonUtil.isNotEmpty(model.getIs_receipt()))
            porders.setIs_receipt(model.getIs_receipt());
        else
            porders.setIs_receipt(0);
        if(CommonUtil.isNotEmpty(model.getFlight_regulation()))
            porders.setFlight_regulation(model.getFlight_regulation());

        return porders;
    }

    public Integer getBusines_order_id() {
        return busines_order_id;
    }

    public void setBusines_order_id(Integer busines_order_id) {
        this.busines_order_id = busines_order_id;
    }
    public String getOrder_code() {
        return order_code;
    }

    public void setOrder_code(String order_code) {
        this.order_code = order_code;
    }
    public Date getCreate_date() {
        return create_date;
    }

    public void setCreate_date(Date create_date) {
        this.create_date = create_date;
    }
    public Date getOrder_time() {
        return order_time;
    }

    public void setOrder_time(Date order_time) {
        this.order_time = order_time;
    }
    public String getBusines_species() {
        return busines_species;
    }

    public void setBusines_species(String busines_species) {
        this.busines_species = busines_species;
    }
    public String getMerchant_code() {
        return merchant_code;
    }

    public void setMerchant_code(String merchant_code) {
        this.merchant_code = merchant_code;
    }
    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }
    public String getCid_merchant() {
        return cid_merchant;
    }

    public void setCid_merchant(String cid_merchant) {
        this.cid_merchant = cid_merchant;
    }
    public String getCustomer_id() {
        return customer_id;
    }

    public void setCustomer_id(String customer_id) {
        this.customer_id = customer_id;
    }
    public String getOrder_status() {
        return order_status;
    }

    public void setOrder_status(String order_status) {
        this.order_status = order_status;
    }
    public String getOrder_tag() {
        return order_tag;
    }

    public void setOrder_tag(String order_tag) {
        this.order_tag = order_tag;
    }
    public String getFinance_status() {
        return finance_status;
    }

    public void setFinance_status(String finance_status) {
        this.finance_status = finance_status;
    }
    public Integer getAdult_num() {
        return adult_num;
    }

    public void setAdult_num(Integer adult_num) {
        this.adult_num = adult_num;
    }
    public Integer getChildren_num() {
        return children_num;
    }

    public void setChildren_num(Integer children_num) {
        this.children_num = children_num;
    }
    public Integer getInf_num() {
        return inf_num;
    }

    public void setInf_num(Integer inf_num) {
        this.inf_num = inf_num;
    }
    public Double getOrder_all_price() {
        return order_all_price;
    }

    public void setOrder_all_price(Double order_all_price) {
        this.order_all_price = order_all_price;
    }
    public Double getSale_price() {
        return sale_price;
    }

    public void setSale_price(Double sale_price) {
        this.sale_price = sale_price;
    }
    public Double getTax() {
        return tax;
    }

    public void setTax(Double tax) {
        this.tax = tax;
    }
    public Integer getI_num() {
        return i_num;
    }

    public void setI_num(Integer i_num) {
        this.i_num = i_num;
    }
    public Double getI_price() {
        return i_price;
    }

    public void setI_price(Double i_price) {
        this.i_price = i_price;
    }
    public Double getExpress_price() {
        return express_price;
    }

    public void setExpress_price(Double express_price) {
        this.express_price = express_price;
    }
    public Double getService_price() {
        return service_price;
    }

    public void setService_price(Double service_price) {
        this.service_price = service_price;
    }
    public Double getOther_price() {
        return other_price;
    }

    public void setOther_price(Double other_price) {
        this.other_price = other_price;
    }
    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }
    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getPhone_number() {
        return phone_number;
    }

    public void setPhone_number(String phone_number) {
        this.phone_number = phone_number;
    }
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
    public Integer getIs_lock() {
        return is_lock;
    }

    public void setIs_lock(Integer is_lock) {
        this.is_lock = is_lock;
    }
    public String getLock_user() {
        return lock_user;
    }

    public void setLock_user(String lock_user) {
        this.lock_user = lock_user;
    }
    public Integer getIs_examine() {
        return is_examine;
    }

    public void setIs_examine(Integer is_examine) {
        this.is_examine = is_examine;
    }
    public Integer getIs_effect() {
        return is_effect;
    }

    public void setIs_effect(Integer is_effect) {
        this.is_effect = is_effect;
    }
    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
    public String getExamine_er() {
        return examine_er;
    }

    public void setExamine_er(String examine_er) {
        this.examine_er = examine_er;
    }
    public Date getExamine_time() {
        return examine_time;
    }

    public void setExamine_time(Date examine_time) {
        this.examine_time = examine_time;
    }
    public Date getStart_datetime() {
        return start_datetime;
    }

    public void setStart_datetime(Date start_datetime) {
        this.start_datetime = start_datetime;
    }
    public Date getEnd_datetime() {
        return end_datetime;
    }

    public void setEnd_datetime(Date end_datetime) {
        this.end_datetime = end_datetime;
    }
    public Integer getIs_receipt() {
        return is_receipt;
    }

    public void setIs_receipt(Integer is_receipt) {
        this.is_receipt = is_receipt;
    }
    public String getFlight_regulation() {
        return flight_regulation;
    }

    public void setFlight_regulation(String flight_regulation) {
        this.flight_regulation = flight_regulation;
    }
    public String getLink_type() {
        return link_type;
    }

    public void setLink_type(String link_type) {
        this.link_type = link_type;
    }
    public String getLink_merchantCode() {
        return link_merchantCode;
    }

    public void setLink_merchantCode(String link_merchantCode) {
        this.link_merchantCode = link_merchantCode;
    }

    @Override
    public String toString() {
        return "PublicOrders{" +
        "busines_order_id=" + busines_order_id +
        ", order_code=" + order_code +
        ", create_date=" + create_date +
        ", order_time=" + order_time +
        ", busines_species=" + busines_species +
        ", merchant_code=" + merchant_code +
        ", source=" + source +
        ", cid_merchant=" + cid_merchant +
        ", customer_id=" + customer_id +
        ", order_status=" + order_status +
        ", order_tag=" + order_tag +
        ", finance_status=" + finance_status +
        ", adult_num=" + adult_num +
        ", children_num=" + children_num +
        ", inf_num=" + inf_num +
        ", order_all_price=" + order_all_price +
        ", sale_price=" + sale_price +
        ", tax=" + tax +
        ", i_num=" + i_num +
        ", i_price=" + i_price +
        ", express_price=" + express_price +
        ", service_price=" + service_price +
        ", other_price=" + other_price +
        ", contact=" + contact +
        ", telephone=" + telephone +
        ", phone_number=" + phone_number +
        ", address=" + address +
        ", is_lock=" + is_lock +
        ", lock_user=" + lock_user +
        ", is_examine=" + is_examine +
        ", is_effect=" + is_effect +
        ", remark=" + remark +
        ", examine_er=" + examine_er +
        ", examine_time=" + examine_time +
        ", start_datetime=" + start_datetime +
        ", end_datetime=" + end_datetime +
        ", is_receipt=" + is_receipt +
        ", flight_regulation=" + flight_regulation +
        ", link_type=" + link_type +
        ", link_merchantCode=" + link_merchantCode +
        "}";
    }
}
